using System;
using Services;
using Utilities;
using System.Linq;
using JigLibX.Physics;
using JigLibX.Geometry;
using System.Threading;
using JigLibX.Collision;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.GamerServices;

namespace WAS.Logic.SampleLevel
{
    using Game = Microsoft.Xna.Framework.Game;

    public abstract class ShockWavesLayer : AsteroidsLayer
    {
        public ShockWavesLayer(Game game, BaseLevelStats current_score, int num_lives)
            : base(game, current_score, num_lives)
        {
        }

        protected override void UpdateShockWaves(float dt)
        {
            var slow_motion = CurrentState.slow_motion;
            var current_score = CurrentScore;

            /// Aggiorno le shockwaves
            for (int i = 0; i < CurrentState.shockwaves.Count; i++)
            {
                var sw = CurrentState.shockwaves[i];

                sw.radius += sw.speed * dt;
                if (sw.radius > sw.range)
                {
                    CurrentState.RemoveShockWaveAt(i);
                    i--;
                }
            }
        }

        protected override void ShootShockWave(Vector3 newposition, Faction newfaction, Color newinitialColor, Color newfinalColor, float newrange, float newspeed, float newdamage, Ship shooter,bool audio)
        {
            var sw = new ShockWave(true)// costruttore NON di default: alloca questa reference nel pool
            {
                position = newposition,
                faction = newfaction,
                initialColor = newinitialColor,
                finalColor = newfinalColor,
                range = newrange,
                speed = newspeed,
                damage = newdamage,
                radius = 0.0f,
                shooter = shooter
            };
            CurrentState.shockwaves.Add(sw);
            NewShockWaves.Add(sw);
            if(audio)
                if (CurrentState.slow_motion_timer == 0)
                    audio_service.OnShockwaveShoot(1);
                else
                    audio_service.OnShockwaveShoot(3);
        }

        protected override void ShootShockWave(Vector3 newposition, Faction newfaction, Color newinitialColor, Color newfinalColor, float newrange, float newspeed, float newdamage, Ship shooter)
        {
            var sw = new ShockWave(true)// costruttore NON di default: alloca questa reference nel pool
            {
                position = newposition,
                faction = newfaction,
                initialColor = newinitialColor,
                finalColor = newfinalColor,
                range = newrange,
                speed = newspeed,
                damage = newdamage,
                radius = 0.0f,
                shooter = shooter
            };
            CurrentState.shockwaves.Add(sw);
            NewShockWaves.Add(sw);
            if (CurrentState.slow_motion_timer == 0)
                audio_service.OnShockwaveShoot(1);
            else
                audio_service.OnShockwaveShoot(3);
        }

    }
}